import Taro, { Component } from '@tarojs/taro'
import { View, Text, Image } from '@tarojs/components'
import './me.scss'

import defaultUserImg from '../../assets/images/icon/user.png'

export default class Me extends Component {

  constructor (props) {
    super(props)
    this.state = {
      userInfo: ''
    }
  }
  componentWillMount () {
    console.log('加载....22')
  }

  componentDidMount () {
  }

  componentWillUnmount () { }

  componentDidShow () {
    let _this = this
    Taro.getSetting({
      success(res) {
        if (!res.authSetting['scope.userInfo']) {
          Taro.navigateTo({
            url: '/pages/auth/auth'
          })
        } else {
          Taro.getUserInfo({
            success: function(user) {
              console.log(user.userInfo)
              _this.setState({
                userInfo: user.userInfo
              })
            }
          })
          console.log('用户信息已授权')

        }
      },
      fail: () => {
        console.log('getSetting 失败')
      }
    })
  }

  componentDidHide () { }

  render () {

    return (
      <View className='myCenter'>
        <View className='myCenter_header'>
          <View  className='header_img'>
            <Image className='taro-img' src={this.state.userInfo.avatarUrl || defaultUserImg}></Image>
          </View>
          <View className='header_nickName'>
            {this.state.userInfo.nickName || '登录'}
          </View>
        </View>

        <View className='myCenter_order_wrap'>
            <View className='myCenter_order'>

            </View>
        </View>
        <Text>个人中心</Text>
      </View>
    )
  }
}

